package com.pingbu.tijian.hospital.backapi.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pingbu.common.bean.ResultBean;
import com.pingbu.common.utils.PbSecretUtils;
import com.pingbu.tijian.hospital.backapi.bean.entity.BuzhiZuoye;
import com.pingbu.tijian.hospital.backapi.bean.entity.Student;
import com.pingbu.tijian.hospital.backapi.bean.entity.StudentGroup;
import com.pingbu.tijian.hospital.backapi.bean.entity.StudentZuoye;
import com.pingbu.tijian.hospital.backapi.config.GlobalConst;
import com.pingbu.tijian.hospital.backapi.mapper.*;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentZuoyeStatistService {

    private static Logger logger = LoggerFactory.getLogger(StudentZuoyeStatistService.class);

    @Autowired
    private StudentZuoyeStatistMapper studentZuoyeStatistMapper;

    /**
     * 统计所有的布置作业的数量
     * @return
     */
    public ResultBean<Integer> getAllBuzhiZuoyeCount(){

        // 由于要获取所有的布置作业数量，所以没有条件
        BuzhiZuoye bzzy = new BuzhiZuoye();
        Integer cnt1 =  studentZuoyeStatistMapper.getBuzhiZuoyeCount(bzzy);
        return ResultBean.create(0,"success",cnt1);
    }

    public ResultBean<List<Map>> getPie1Data(){

        // 读取作业的完成情况数据
        StudentZuoye stzy1 = new StudentZuoye();
        Integer cntAll =  studentZuoyeStatistMapper.getStudentZuoyeCount(stzy1);

        // 设置条件为已完成的
        StudentZuoye stzy2 = new StudentZuoye();
        stzy2.setWancheng_status(GlobalConst.Student_Zuoye_Wancheng_Status_Yi_Wancheng);
        Integer cntYiwancheng =  studentZuoyeStatistMapper.getStudentZuoyeCount(stzy2);

        // 设置条件未未审核的
        StudentZuoye stzy3 = new StudentZuoye();
        stzy3.setWancheng_status(GlobalConst.Student_Zuoye_Wancheng_Status_No_Exam);
        Integer cntWeishenhe =  studentZuoyeStatistMapper.getStudentZuoyeCount(stzy3);

        Map<String,Object> map1 = new HashMap<>();
        map1.put("name","未审核");
        map1.put("value",cntWeishenhe);

        Map<String,Object> map2 = new HashMap<>();
        map2.put("name","已完成");
        map2.put("value",cntYiwancheng);

        Map<String,Object> map3 = new HashMap<>();
        map3.put("name","未完成");
        map3.put("value",cntAll - cntWeishenhe - cntYiwancheng);

        List<Map> lst1 = new ArrayList<>();
        lst1.add(map1);
        lst1.add(map2);
        lst1.add(map3);


        return ResultBean.create(0,"success",lst1);
    }


    public ResultBean<Integer> getStudentCount() {
        Student student = new Student();
        Integer cnt1 =  studentZuoyeStatistMapper.getStudentCount(student);
        return ResultBean.create(0,"success",cnt1);
    }
}
